//
//  LBDebugModule.m
//  LBReact
//
//  Created by WuShiHai on 19/5/24.
//  Copyright (c) 2019 Lebbay. All rights reserved.
//

#import "LBDebugModule.h"
#import "LBRConstants.h"

#import <LBFoundation/LBFoundation.h>
#import <LBUIKit/LBUIKit.h>
#import <LBDebugBall/DBNetworkLogDataBase.h>
#import <React/RCTConvert.h>

@implementation LBDebugModule

RCT_EXPORT_MODULE(nativeDebug)

RCT_EXPORT_METHOD(logRequest:(NSDictionary *)paremeters) {
    DBNetworkLogModel *model = [[DBNetworkLogModel alloc] init];
    model.uriString = [RCTConvert NSString:[paremeters objectForKey:@"url"]];
    model.method = [RCTConvert NSString:[paremeters objectForKey:@"method"]];
    model.header = [RCTConvert NSDictionary:[paremeters objectForKey:@"headers"]];
    model.parameters = [paremeters objectForKey:@"requestBody"];
    model.code = [RCTConvert NSString:[paremeters objectForKey:@"responseCode"]];
    model.responseObject = [RCTConvert NSString:[paremeters objectForKey:@"responseBody"]];

    [DBNetworkLogDataBase insertNetworkLog:model];
}

@end
